import Mock from 'mockjs'

const Random = Mock.Random // Mock.Random 是一个工具类，用于生成各种随机数据

const dataList = [] // 用于接受生成数据的数组

for (let i = 0; i < 1001; i++) { // 可自定义生成的个数
  
  const template = {
    
    'id': Random.increment(),
    'shop_name': Random.cword(8,10),
    'account': Random.word(6,10),
    'categories': [Random.cword(2,5),Random.cword(2,5),Random.cword(2,5)],
    'machine_name': Random.word(6,10),
    'ip': `${Random.natural(0,255)}.${Random.natural(0,255)}.${Random.natural(0,255)}.${Random.natural(0,255)}`,
    'agent_status': Random.natural(1,3),
    'shop_config_status': Random.natural(1,2),
    'plat_config_status': Random.natural(1,2),
    'strategy_config_status': Random.natural(1,2),
    'strategy_status': Random.natural(1,2),
    'bind_time': Random.datetime("yyyy-MM-dd HH:mm:ss"),
    'login_time': Random.datetime("yyyy-MM-dd HH:mm:ss"),
    'status': Random.natural(1,2),
    
  }
  
  dataList.push(template)
  
}

Mock.mock('/api/store/list', 'post', function (params) {
  const {pagenum,pagesize} = JSON.parse(params.body)
  const [index, size, total] = [pagenum, pagesize, dataList.length]
  const len = total / size
  const totalPages = len - parseInt(len) > 0 ? parseInt(len) + 1 : len
  const newDataList = dataList.slice(index * size, (index + 1) * size)
  const res = Mock.mock({
    code: 200,
    msg: '获取店铺列表成功',
    data: {
      list: newDataList,
      pagenum: index,
      pagesize: size,
      total,
      totalPages
    }})
  return res
})